Package edu.uky.ai.path
Class PriorityQueue<T>
java.lang.Object
edu.uky.ai.path.PriorityQueue<T>
- Type Parameters:
T- the type of object to be stored in the queue
- All Implemented Interfaces:
java.lang.Iterable<T>
public class PriorityQueue<T>
extends java.lang.Object
implements java.lang.Iterable<T>
A priority queue is a collection of things which, after being put in (or
"pushed") can be taken out ("popped) in the order defined by the numeric
key associated with each thing. This is a min priority queue, meaning that
the thing with the smallest key will always be removed next.
- Author:
- Stephen G. Ware
-
Constructor Summary
Constructors Constructor Description PriorityQueue()Creates a new min priority queue. -
Method Summary
Modifier and Type Method Description booleancontains(java.lang.Object object)Tests whether or not a given object is stored in the queue.voidforEach(java.util.function.Consumer<? super T> consumer)java.util.Iterator<T>iterator()Tpeek()Returns the next object to be removed from the queue.Tpop()Removes the object with the lowest key from the queue and returns it.voidpush(T element, double key)Adds an object to the queue and associates the object with a numeric key that will be used to determine in what order the object comes out.intsize()Returns the number of elements current stored in the queue.
-
Constructor Details
-
PriorityQueue
public PriorityQueue()Creates a new min priority queue.
-
-
Method Details
-
iterator
- Specified by:
iteratorin interfacejava.lang.Iterable<T>
-
forEach
- Specified by:
forEachin interfacejava.lang.Iterable<T>
-
size
public int size()Returns the number of elements current stored in the queue.- Returns:
- the number of elements
-
contains
public boolean contains(java.lang.Object object)Tests whether or not a given object is stored in the queue.- Parameters:
object- the object to test- Returns:
- true if the object is in the queue, false otherwise
-
peek
Returns the next object to be removed from the queue.- Returns:
- the next (minimum) object, or null if the queue is empty
-
push
Adds an object to the queue and associates the object with a numeric key that will be used to determine in what order the object comes out.- Parameters:
element- the object to addkey- the numeric key associated with the object
-
pop
Removes the object with the lowest key from the queue and returns it.- Returns:
- the object with the lowest key
-